﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using RiskMan.DataClass.Models.NotBasModels;
using RiskMan.Views.Dialogs;

namespace RiskMan.Config
{
    /// <summary>
    /// Interaction logic for TamplateTimeWorking.xaml
    /// </summary>
    public partial class TamplateTimeWorking : Window
    {
        public TamplateTimeWorking()
        {
            InitializeComponent();
            dtgdTamplate.ItemsSource = MainWindow.StaticLevel._dataProvider.TamplateTimeWorkingList;
            TamplateTimeWorkingExhange workDay = new TamplateTimeWorkingExhange()
            {

                Name = "Рабочий день", 
                StartTimeMmvb = new TimeSpan(10,0,0),
                EndTimeMmvb = new TimeSpan(18, 45, 0), 
                StartTimeForts = new TimeSpan(10,0,0),
                EndTimeForts = new TimeSpan(23,50,00),
                StartDayKliring = new TimeSpan(14,0,0),
                EndDayKliring = new TimeSpan(14,3,0),
                StartEveningKliring = new TimeSpan(18,45,0),
                EndEveningKliring = new TimeSpan(21,0,0)

            };
            TamplateTimeWorkingExhange sundayDay = new TamplateTimeWorkingExhange() {Name="Выходной день"};
            if (MainWindow.StaticLevel._dataProvider.TamplateTimeWorkingList.Count(a => a.Name == workDay.Name)==0)
            {
                MainWindow.StaticLevel._dataProvider.TamplateTimeWorkingList.Add(workDay);
            }
            if (MainWindow.StaticLevel._dataProvider.TamplateTimeWorkingList.Count(a => a.Name == sundayDay.Name) == 0)
            {
                MainWindow.StaticLevel._dataProvider.TamplateTimeWorkingList.Add(sundayDay);
            }
            dtgdTamplate.SelectedIndex = 0;
        }

        private void Button_AddRow_Click(object sender, RoutedEventArgs e)
        {
             MainWindow.StaticLevel._dataProvider.TamplateTimeWorkingList.Add(new TamplateTimeWorkingExhange() {Name = "Новый шаблон"});
            dtgdTamplate.SelectedIndex = MainWindow.StaticLevel._dataProvider.TamplateTimeWorkingList.Count - 1;

            TxbxName.IsEnabled = true;
            GpbxMMVB.IsEnabled = true;
            GpbxFORTS.IsEnabled = true;
        }

        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (dtgdTamplate.SelectedItems.Count == 1)
                try
                {
                    if (
                        new DialogOkCancel("Вы действительно хотите удалить шаблон ?", "Внимание")
                            .Result == MessageBoxResult.OK)
                    {
                        MainWindow.StaticLevel._dataProvider.TamplateTimeWorkingList.Remove(
                            dtgdTamplate.SelectedItem as TamplateTimeWorkingExhange);
                    }
                }
                catch
                {
                }
        }

        private void dtgdTamplate_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            TxbxName.IsEnabled = true;
            GpbxMMVB.IsEnabled = true;
            GpbxFORTS.IsEnabled = true;
        }
    }
}
